# This is the main file to be used for Human Activity recognition.
# Please keep this file to minimum.
import sys
import getopt
import constants

# Local 
from har import HumanActivityRecognition
import doc


"""Module docstring.
"""
# --
# Main function calls from here
# TODO: sanitize input.
# --
def main(argv):
    iface = ""
    freq = 0
    mode = 2
    try:
        opts, args = getopt.getopt(sys.argv[1:], "hdi:f:", ["help","debug","iface","freq"])
    except getopt.GetoptError:
        print "Option error!"
        doc.usage()
        sys.exit(2)
    for opt, arg in opts:
        if opt in ("-h","--help"):
            doc.usage()
            sys.exit()
        elif opt in("-d","--debug"):
            mode = constants.DEBUG_MODE
    	    #har = HumanActivityRecognition(constants.DEBUG_MODE,None)
            #har.initiate()
        elif opt in("-i","--iface"):
            iface = arg
            #har = HumanActivityRecognition(constants.RUN_MODE,str(iface))
            #har.initiate()
        elif opt in("-f","--freq"): # This frequency is in the seconds
            print "XXXXXX"
            freq = int(arg)
            print freq
            if(freq < constants.MIN_FREQ):
                freq = constants.MIN_FREQ
                print "Setting Frequency to: ",constants.MIN_FREQ
            #har = HumanActivityRecognition(constants.RUN_MODE,str(iface),int(freq))
            #har.initiate()
        else:
            assert False, "Unhandled Option"
            doc.usage()
        har = HumanActivityRecognition(mode,str(iface),int(freq))
        har.initiate()

if __name__ == "__main__":
    main(sys.argv[1:])
